/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package api.purchase;

import Model.Purchase.ApiMaterielDetailsView;
import Model.Purchase.PurchaseList;
import Model.Purchase.PurchaseMaterielOfferList;
import RssEasy.Core.HttpRequestHelper;
import RssEasy.Core.ServletRequestHelper;
import RssEasy.Core.SignVerifyRequestHelper;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author zhangwenbo
 */
@WebServlet(name = "api_purchse_details", urlPatterns = {"/api/purchase/details"})
public class details extends ServletRequestHelper{
    @Override
    public HttpRequestHelper request(HttpServletRequest request,HttpServletResponse response) {
        super.request(request,response);
        try {
            ApiMaterielDetailsView purchase=new ApiMaterielDetailsView(this.pageContext);
            PurchaseList pl=new PurchaseList(this.pageContext);
            PurchaseMaterielOfferList pmol=new PurchaseMaterielOfferList(this.pageContext);
            pl.request();
            pl.select("name,enddt").where("id=?",this.get("purchaseid")).get_page_desc("id");
            purchase.request();
            purchase.select("purchaseid,id,materielname,model,amout,unit,attachurl").where("purchaseid=?",this.get("purchaseid")).get_page_desc("id");
            pmol.request();
            pmol.select("price,addr,materielid,enddt,freight,spotgoods,icourl,judge,taxpoint").where("myid=? and purchaseid=?",this.get("myid"),this.get("purchaseid")).get_page_asc("id");
            out.print("{\"purchase\":"+pl.toKeyValue()+",\"materiel\":"+purchase.toKeyValue()+",\"offer\":"+pmol.toKeyValue()+"}");
        } catch (Exception e) {
            out.print("{\"rsscode\":" + e.getMessage() + "}");
        }
        return this;
    }
}
